<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .first-com{
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="div">
        父组件的msg:{{num}}<br>
        <!-- v-bind +  input 事件 v-model -->
        <first-com  :num="num" @click="rootAdd"></first-com>
        

    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.4/axios.min.js"></script>

    <script>
        //app本生也是组件，根(root)组件
        const app = Vue.createApp({
            data(){
                return{
                    num:0,
  
                }
            },
            methods:{
                rootAdd(e){
                    //e:事件对象
                    console.log(e);
                }
            }

        });
        //子组件
        // num++  :  num=num+1   num+1  1
        //自定义事件: emit(发送) -->  on
        //           $emit     -->   v-on
        //
        app.component('FirstCom',{
            template:`
                <div class="first-com">
                    <button @click="onAdd">点击</button>
                </div>
            `,
            props:["num"],    //modelValue:v-model默认绑定状态
            methods: {
                onAdd(){
                    //
                    this.$emit('click',this.num+1);
                }
            },
            //书写习惯
            emits:['click']
        });

        app.mount('#div')

    </script>

</body>

</html>